/*
 * @Author: 悦者生存 1002783067@qq.com
 * @Date: 2023-03-11 14:58:59
 * @LastEditors: 悦者生存 1002783067@qq.com
 * @LastEditTime: 2024-04-25 20:38:57
 * @FilePath: /koa2-ts-template/src/api/upload/upload.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import fs from 'fs-extra';
import { Models } from '../../common/typings/model';
import { routeConfig } from 'koa-swagger-decorator';
import { uploadFile } from '../../common/utils/file';

interface File {
  filepath: fs.PathLike;
  originalFilename: string;
}

class UploadController {
  @routeConfig({
    method: 'post',
    path: '/upload',
    summary: '上传图片',
    tags: ['UPLOAD'],
  })
  async uploadFile(ctx: Models.Ctx) {
    const file = ctx.request?.files?.file as unknown as File;
    uploadFile(file, ctx);
  }
}

export default UploadController;
